package com.example.demo.poc.example;

import com.taosdata.jdbc.TSDBDriver;

import java.sql.*;
import java.util.Properties;

public class TaosJDBCTest {

    public static void main(String[] args) throws Exception {

        Connection conn = getConn();
        conn.setAutoCommit(true);
        PreparedStatement psmt = conn.prepareStatement("select * from log.log");
        ResultSet rs = psmt.executeQuery();
        System.out.println(rs.next());
        while(rs.next()){
            String time = rs.getString(1);
            System.out.println(time);
        }
        rs.close();


    }
    public static Connection getConn() throws Exception{
        Class.forName("com.taosdata.jdbc.TSDBDriver");
        // Class.forName("com.taosdata.jdbc.rs.RestfulDriver");
        String jdbcUrl = "jdbc:TAOS://nts1:6030/log?user=root&password=taosdata&timezone=UTC-8";
        // String jdbcUrl = "jdbc:TAOS-RS://taosdemo.com:6041/test?user=root&password=taosdata";
        Properties connProps = new Properties();
        connProps.setProperty(TSDBDriver.PROPERTY_KEY_CHARSET, "UTF-8");
        connProps.setProperty(TSDBDriver.PROPERTY_KEY_LOCALE, "en_US.UTF-8");
//        connProps.setProperty(TSDBDriver.PROPERTY_KEY_TIME_ZONE, "UTC-8");
        Connection conn = DriverManager.getConnection(jdbcUrl, connProps);
        return conn;
    }
}
